package com.um.springboot.starter.orm.controller;


import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.entity.BaseDTO;
import com.um.springboot.starter.orm.entity.BaseEntity;
import com.um.springboot.starter.orm.entity.BaseVO;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.manager.BaseCMSManager;
import com.um.springboot.starter.orm.manager.BasePlusManager;
import com.um.springboot.starter.orm.params.*;
import com.um.springboot.starter.orm.service.BaseEntityService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 邓南辉
 * 日期 2023/2/6
 * 版权所有 广州优匠科技有限公司
 */
@Validated
public class BasePlusController<M extends BasePlusManager<S, E, D, V, P,L>,
        S extends BaseEntityService<E>,
        E extends BaseEntity,
        D extends BaseDTO,
        V extends BaseVO,
        P extends PageDTO,
        L extends ListDTO> extends BaseController<M>{

    final String str = getClass().getSimpleName();

    @ApiOperation("列表")
    @ApiPermission("list")
    @PostMapping("list")
    public Response<List<E>> list(@RequestBody L params) {
        return manager.list(params);
    }

    @ApiOperation("分页列表")
    @ApiPermission("page")
    @PostMapping("page")
    public Response<Page<E>> page(@RequestBody P params) {
        return manager.page(params);
    }

    @ApiOperation("新增")
    @ApiPermission("add")
    @PostMapping
    public Response<E> add(@RequestBody D dto) {
         return manager.addEntity(dto);
    }

    @ApiOperation("更新")
    @ApiPermission("update")
    @PutMapping("{id}")
    public  Response<E> update(@PathVariable String id, @RequestBody D dto) {
        return manager.updateEntity(id, dto);
    }

    @ApiOperation("启用、禁用")
    @ApiPermission("enable")
    @PutMapping("{id}/enable")
    public Response<Object> enable(@PathVariable String id, @RequestParam String enable) {
        return manager.enable(id, enable);

    }

    @ApiOperation("排序")
    @ApiPermission("sort")
    @PutMapping("{id}/sort")
    public Response<Object> sort(@PathVariable String id, @RequestParam int sort) {
        return manager.sort(id, sort);
    }

    @ApiOperation("详情")
    @ApiPermission("get")
    @GetMapping("{id}")
    public Response<V> get(@PathVariable String id) {
        return manager.get(id);
    }

    @ApiOperation("删除")
    @ApiPermission("delete")
    @DeleteMapping("{id}")
    public Response<Object> delete(@PathVariable String id) {
        return manager.delete(id);
    }

    @ApiOperation("批量删除")
    @ApiPermission("delete_all")
    @DeleteMapping
    public Response<Object> deleteIds(@ApiParam(value = "删除的id", required = true) @RequestBody List<String> ids) {
        return manager.deleteIds(ids);
    }

}
